package com.kwq.designPattern.construct.Filter;

import java.util.List;
import java.util.ArrayList;

/**
 * @author kangwanqiang
 * @date 2021/2/6
 * @description 客户端类
 */
public class CriteriaClientDemo {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<>();

        persons.add(new Person("Robert", 1, 0));
        persons.add(new Person("John", 1, 1));
        persons.add(new Person("Laura", 0, 1));
        persons.add(new Person("Diana", 0, 0));
        persons.add(new Person("Mike", 1, 0));
        persons.add(new Person("Bobby", 1, 0));

        Criteria male = new CriteriaMaleImpl();
        Criteria female = new CriteriaFemaleImpl();
        Criteria single = new CriteriaMaritalStatusImpl();
        Criteria singleMale = new AndCriteria(single, male);
        Criteria singleOrFemale = new OrCriteria(single, female);

        System.out.println("Males: ");
        printPersons(male.meetCriteria(persons));

        System.out.println("\nFemales: ");
        printPersons(female.meetCriteria(persons));

        System.out.println("\nSingle Males: ");
        printPersons(singleMale.meetCriteria(persons));

        System.out.println("\nSingle Or Females: ");
        printPersons(singleOrFemale.meetCriteria(persons));
    }

    public static void printPersons(List<Person> persons) {
        for (Person person : persons) {
            System.out.println("Person : [ Name : " + person.getName()
                    + ", Gender : " + person.getGender() + ", Marital Status : "
                    + person.getMaritalStatus() + " ]");
        }
    }
}
